package com.m4399.shortcut_test.setting

import android.content.Context
import android.os.Build
import android.util.Log
import com.m4399.shortcut_test.setting.ShortcutPermissionChecker.checkNubia
import com.m4399.shortcut_test.setting.ShortcutPermissionChecker.checkOnEMUI
import com.m4399.shortcut_test.setting.ShortcutPermissionChecker.checkOnMIUI
import com.m4399.shortcut_test.setting.ShortcutPermissionChecker.checkOnOPPO
import com.m4399.shortcut_test.setting.ShortcutPermissionChecker.checkOnVIVO

/**
 * Created by ZP on 2019-12-02.
 */
object ShortcutPermission {
    private const val TAG = "ShortcutPermission"

    /**
     * Permission check result: this is returned by [.check]
     * if the permission has been granted to the given package.
     */
    const val PERMISSION_GRANTED = 0

    /**
     * Permission check result: this is returned by [.check]
     * if the permission has not been granted to the given package.
     */
    const val PERMISSION_DENIED = -1
    const val PERMISSION_ASK = 1
    const val PERMISSION_UNKNOWN = 2
    const val PERMISSION_EXCEPTION = 3
    private val MARK = Build.MANUFACTURER.toLowerCase()
    fun check(context: Context): Int {
        Log.d(TAG, "manufacturer = " + MARK + ", api level= " + Build.VERSION.SDK_INT)
        var result = PERMISSION_UNKNOWN
        when {
            MARK.contains("huawei") || MARK.contains("honor",true) -> {
                result = checkOnEMUI(context)
            }
            MARK.contains("xiaomi") -> {
                result = checkOnMIUI(context)
            }
            MARK.contains("oppo") -> {
                result = checkOnOPPO(context)
            }
            MARK.contains("vivo") -> {
                result = checkOnVIVO(context)
            }
            MARK.contains("samsung") || MARK.contains("meizu") -> {
                result = PERMISSION_GRANTED
            }
            MARK.contains("360") -> {
                result = PERMISSION_GRANTED
            }
            MARK.contains("nubia") -> {
                result = checkNubia(context)
            }
        }
        return result
    }
}